package com.kotlinvben.entity

import com.fasterxml.jackson.annotation.JsonFormat
import com.kotlinvben.enumeration.Status
import jakarta.persistence.*
import org.hibernate.annotations.CreationTimestamp
import org.hibernate.annotations.DynamicUpdate
import org.hibernate.annotations.SoftDelete
import org.hibernate.annotations.UpdateTimestamp
import java.time.LocalDateTime

@Entity
@Table(name = "departments")
@SoftDelete(columnName = "deleted")
@DynamicUpdate
data class Department(
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    val id: Long? = null,

    @Column(nullable = false, length = 50)
    var name: String? = null,

    @Column(length = 500)
    var remarks: String? = null,

    @Column(nullable = true)
    var status: Int = Status.ENABLED.code,

    @Column(nullable = false, insertable = false, updatable = false)
    var deleted: Boolean = false,

    @Column(nullable = true)
    var pid: Long? = null,

    @Column(nullable = false)
    var sort: Int = 0,

    @CreationTimestamp
    @Column(nullable = false, updatable = false)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    var createTime: LocalDateTime? = null,

    @Column(nullable = false, length = 50)
    var createBy: String? = null,

    @UpdateTimestamp
    @Column(nullable = false)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    var modifyTime: LocalDateTime? = null,

    @Column(nullable = false, length = 50)
    var modifyBy: String? = null,

    @Transient
    var children: MutableList<Department>? = null
)